package com.pickme.food.common.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Swagger 文档配置类，URI：/doc.html
 */

@Configuration
@EnableSwagger2 //启用 Swagger 支持
@EnableKnife4j  //启用 Knife4j 增强注解
public class SwaggerConfig {

    /**
     * 基于 Swagger 的api文档生成器
     * @return
     */
    @Bean
    public Docket createRestApi() {
        // 文档类型
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.pickme.food.controller")) //包扫描路径
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * 构建api文档生成信息
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("南华味来美食馆")
                .version("1.0")
                .description("南华味来美食馆项目接口文档")
                .build();
    }
}
